﻿using PLC.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PLC
{
    public class EnvDataManagerStub : IEnvDataManager
    {

        public EnvDataManagerStub()
        { }


        //int experimentType;
        //int pumpType;

        bool isConnected;

        public bool IsConnected { get => isConnected; }
        //public int ExperimentType { get => experimentType; set => experimentType = value; }
        //public int PumpType { get => pumpType; set => pumpType = value; }

        public void Connect()
        {

            isConnected = true;
        }

        public void Close()
        {

            isConnected = false;
        }

        int index = 0;
        Double[,] datas = new Double[,]
        {

/*{ 0.00  ,  -0.42 ,  819.78 , 4.91 ,   383.99 , 2.21*1000  ,  2974.77, 19.870001   },
{ 7.51  ,  -0.44  , 796.27 , 6.87 ,   387.45,  3.80*1000 ,   2958.50, 19.870001  },
{ 8.82  ,  -0.56  , 785.24,  7.23 ,   387.44,  4.06*1000 ,   2956.33, 19.870001  },
{ 11.33 ,  -0.53  , 756.67 , 7.85  ,  387.20,  4.51*1000 ,   2950.36 ,19.870001 },
{ 12.55 ,  -0.44  , 737.68 , 8.29  ,  387.25 , 4.82*1000 ,   2946.29 ,19.870001  },
{ 13.29 ,  -0.49  , 725.74 , 8.30 ,   387.33 , 4.84*1000 ,   2946.02, 19.870001 },
{ 14.26 ,  -0.53  , 710.55 , 8.51 ,   387.50,  4.97*1000 ,   2945.20, 19.870001 },
{ 16.34 ,  -0.62 ,  674.02 , 8.88 ,   387.58 , 5.23*1000 ,   2944.39 ,19.870001   },
{ 17.93 ,  -0.99  , 638.39 , 9.13  ,  387.30 , 5.40*1000 ,   2941.13 ,19.870001  },
{ 19.60 ,  -0.56  , 595.17 , 9.31  ,  387.50,  5.53*1000 ,   2938.15 ,19.870001 },
{ 22.14 ,  -0.92 ,  524.46 , 9.60 ,   387.45  ,5.73*1000 ,   2935.98, 19.870001  },*/

{ 71.82 ,  0.26,    10.13,   17.15,   392.33,  6.32*1000 ,      563.16, 19.870001 },
{ 72.74,   1.31 ,   9.95  ,  17.17,   392.80,  6.29*1000,         563.16, 19.870001 },
{ 73.38 ,  1.51 ,   106.34 , 18.87,   391.94,  8.19*1000,     562.35, 19.870001 },
{ 71.53,   1.77 ,   201.65,  21.43,   392.94,  10.49*1000,      561.26, 19.870001 },
{ 71.02,   1.89 ,   297.50,  23.21,   391.41,  11.91*1000 ,    561.26, 19.870001 },
{ 70.32,   1.53,    414.14,  26.08,   391.51,  14.10*1000,     560.45, 19.870001 },
{ 69.93 ,  1.67,    508.55,  28.63 ,  390.55,  15.89*1000,      559.09, 19.870001 },
{ 69.22,   1.94 ,   610.00,  31.59,   390.10,  18.00*1000 ,    558.01, 19.870001 }
            };

       



        /// <summary>
        /// 读取数据，需要传入电流变比,后续电流变比也可读
        /// </summary>
        /// <param name="currentTransformationRatio">电流变比</param>
        /// <returns></returns>
        public EnvData ReadData(int dn,double transformationRatio)
        {
            EnvData data = new EnvData();
            data.Flow = datas[index, 0];
            data.PresureIn = datas[index, 1];
            data.PresureOut = datas[index, 2];
            data.Current = datas[index, 3];
            data.Voltage = datas[index, 4];
            data.ShaftPower = datas[index, 5];
            data.Speed = datas[index, 6];
            data.Temperature = datas[index, 7];

            return data;
        }

        public void NextData_Test()
        {
            index++;
            if (index >= datas.Length)
            {
                index = datas.Length - 1;
            }
        }

        public void SetIndexZero()
        {
            index = 0;
        }
    }
}
